home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / rpccmd / RCS / rpccmd.c,v < prev    next >
Encoding:
Text File  |  1992-07-10  |  11.5 KB  |  514 lines

  1. head     1.7;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.6.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.7
  10. date     92.07.10.14.57.28;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.6;
  13.  
  14. 1.6
  15. date     92.07.09.18.26.10;  author jhh;  state Exp;
  16. branches 1.6.1.1;
  17. next     1.5;
  18.  
  19. 1.5
  20. date     90.08.29.17.18.31;  author ouster;  state Exp;
  21. branches ;
  22. next     1.4;
  23.  
  24. 1.4
  25. date     90.08.29.17.02.17;  author mgbaker;  state Exp;
  26. branches ;
  27. next     1.3;
  28.  
  29. 1.3
  30. date     89.08.15.21.11.45;  author jhh;  state Exp;
  31. branches ;
  32. next     1.2;
  33.  
  34. 1.2
  35. date     88.11.11.14.11.19;  author brent;  state Exp;
  36. branches ;
  37. next     1.1;
  38.  
  39. 1.1
  40. date     88.10.31.14.28.23;  author brent;  state Exp;
  41. branches ;
  42. next     ;
  43.  
  44. 1.6.1.1
  45. date     92.07.10.15.43.15;  author kupfer;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @Tool to turn on/off the RPC system, and to toggle debug/tracing switches
  52. inthe RPC system.
  53. @
  54.  
  55.  
  56. 1.7
  57. log
  58. @Fixed includes (<> instead of "").  Added -Creset and -Sreset options.
  59. Fixed call to Opt_Parse.  Lint.
  60. @
  61. text
  62. @/* 
  63.  * rpccmd.c --
  64.  *
  65.  *    User interface to RPC related commands of the Fs_Command system call.
  66.  *
  67.  * Copyright (C) 1986 Regents of the University of California
  68.  * All rights reserved.
  69.  * Permission to use, copy, modify, and distribute this
  70.  * software and its documentation for any purpose and without
  71.  * fee is hereby granted, provided that the above copyright
  72.  * notice appear in all copies.  The University of California
  73.  * makes no representations about the suitability of this
  74.  * software for any purpose.  It is provided "as is" without
  75.  * express or implied warranty.
  76.  */
  77.  
  78. #ifndef lint
  79. static char rcsid[] = "$Header: /sprite/src/cmds/rpccmd/RCS/rpccmd.c,v 1.6 92/07/09 18:26:10 jhh Exp Locker: kupfer $ SPRITE (Berkeley)";
  80. #endif not lint
  81.  
  82. #include <sprite.h>
  83. #include <status.h>
  84. #include <option.h>
  85. #include <stdio.h>
  86. #include <fs.h>
  87. #include <fsCmd.h>
  88. #include <sysStats.h>
  89. #include <rpc.h>
  90. #include <host.h>
  91.  
  92. /*
  93.  * Command line options.
  94.  */
  95.  
  96. int    rpcEnable = -1;
  97. int    rpcDebug = -1;
  98. int    rpcTracing = -1;
  99. int    rpc_NoTimeouts = -1;
  100. int    rpcClientHist = -1;
  101. int    rpcServerHist = -1;
  102. Boolean    resetClientHist = FALSE;
  103. Boolean    resetServerHist = FALSE;
  104. char    *rpcEchoHost = (char *)0;
  105. int    blockSize = 32;
  106. int    rpcMaxServers = -1;
  107. int    rpcNumServers = -1;
  108. int    rpcNegAcks = -1;
  109. int    rpcChannelNegAcks = -1;
  110. int    rpcNumNackBufs = -1;
  111. int    numEchoes = 100;
  112. int    sanityChecks = -1;
  113.  
  114. Option optionArray[] = {
  115.     {OPT_TRUE, "on", (Address) &rpcEnable, 
  116.     "\tAllow servicing of RPC requests."},
  117.     {OPT_FALSE, "off", (Address) &rpcEnable, 
  118.     "\tTurn off servicing of RPC requests."},
  119.     {OPT_STRING, "ping", (Address) &rpcEchoHost, 
  120.     "\tRPC test against the specified host."},
  121.     {OPT_INT, "b", (Address) &blockSize, 
  122.     "\tBlock size to send in RPC test."},
  123.     {OPT_INT, "t", (Address) &rpcTracing, 
  124.     "\tSet rpc tracing flag."},
  125.     {OPT_INT, "T", (Address) &rpc_NoTimeouts, 
  126.     "\tSet rpc no timeouts flag."},
  127.     {OPT_INT, "D", (Address) &rpcDebug, 
  128.     "\tSet rpc debug flag."},
  129.     {OPT_INT, "C", (Address) &rpcClientHist, 
  130.     "\tSet client histogram flag."},
  131.     {OPT_INT, "S", (Address) &rpcServerHist, 
  132.     "\tSet server histogram flag."},
  133.     {OPT_TRUE, "Creset", (Address) &resetClientHist, 
  134.     "\tReset client RPC histograms."},
  135.     {OPT_TRUE, "Sreset", (Address) &resetServerHist, 
  136.     "\tReset server RPC histograms."},
  137.     {OPT_INT, "maxServers", (Address) &rpcMaxServers,
  138.     "\tSet the maximum number of allowed rpc server processes."},
  139.     {OPT_INT, "numServers", (Address) &rpcNumServers,
  140.     "\tCreate more rpc servers until this number exists."},
  141.     {OPT_TRUE, "negAcksOn", (Address) &rpcNegAcks,
  142.     "\tTurn on negative acknowledgements on a server."},
  143.     {OPT_FALSE, "negAcksOff", (Address) &rpcNegAcks,
  144.     "\tTurn off negative acknowledgements on a server (default)."},
  145.     {OPT_INT, "numNackBufs", (Address) &rpcNumNackBufs,
  146.     "\tMake sure this number of negative ack buffers exists."},
  147.     {OPT_TRUE, "channelNegAcksOn", (Address) &rpcChannelNegAcks,
  148.     "\tSet the client policy for handling negative acks to ramp down number of channels."},
  149.     {OPT_FALSE, "channelNegAcksOff", (Address) &rpcChannelNegAcks,
  150.     "\tSet the client policy for handling negative acks to the default backoff policy."},
  151.     {OPT_INT, "numPings", (Address) &numEchoes,
  152.     "\tNumber of pings to send."},
  153.     {OPT_INT, "sanity", (Address)&sanityChecks,
  154.     "\tTurn off/on rpc sanity checks."},
  155.  
  156. };
  157. int numOptions = sizeof(optionArray) / sizeof(Option);
  158.  
  159. /* forward references: */
  160.  
  161. static void ResetClientHist();
  162. static void ResetServerHist();
  163. ReturnStatus SetFlag();
  164.  
  165.  
  166. /*
  167.  *----------------------------------------------------------------------
  168.  *
  169.  * main --
  170.  *
  171.  *    Collects arguments and branch to the code for the fs command.
  172.  *
  173.  * Results:
  174.  *    None.
  175.  *
  176.  * Side effects:
  177.  *    Calls Fs_Command...
  178.  *
  179.  *----------------------------------------------------------------------
  180.  */
  181. main(argc, argv)
  182.     int argc;
  183.     char *argv[];
  184. {
  185.     register ReturnStatus status = SUCCESS;    /* status of system calls */
  186.  
  187.     argc = Opt_Parse(argc, argv, optionArray, numOptions, 0);
  188.  
  189.     /*
  190.      * Set various rpc system flags.  The Fs_Command system call returns
  191.      * the old value of the flag in place of the value passed in.
  192.      */
  193.     if (rpcEnable != -1) {
  194.     status = Sys_Stats(SYS_RPC_ENABLE_SERVICE, rpcEnable, NIL);
  195.     }
  196.     if (rpcTracing != -1) {
  197.     status = SetFlag(FS_SET_RPC_TRACING, rpcTracing, "RPC tracing");
  198.     }
  199.     if (rpc_NoTimeouts != -1) {
  200.     status = SetFlag(FS_SET_RPC_NO_TIMEOUTS, rpc_NoTimeouts,
  201.                         "No RPC timeouts");
  202.     }
  203.     if (rpcDebug != -1) {
  204.     status = SetFlag(FS_SET_RPC_DEBUG, rpcDebug, "RPC debug prints");
  205.     }
  206.     if (rpcClientHist != -1) {
  207.     status = SetFlag(FS_SET_RPC_CLIENT_HIST, rpcClientHist,
  208.                          "Client RPC timing histograms");
  209.     }
  210.     if (rpcServerHist != -1) {
  211.     status = SetFlag(FS_SET_RPC_SERVER_HIST, rpcServerHist,
  212.                         "Server RPC timing histograms");
  213.     }
  214.     if (resetClientHist) {
  215.     ResetClientHist();
  216.     }
  217.     if (resetServerHist) {
  218.     ResetServerHist();
  219.     }
  220.     if (rpcMaxServers != -1) {
  221.     status = Sys_Stats(SYS_RPC_SET_MAX, rpcMaxServers, NIL);
  222.     }
  223.     if (rpcNumServers != -1) {
  224.     status = Sys_Stats(SYS_RPC_SET_NUM, rpcNumServers, NIL);
  225.     }
  226.     if (rpcNegAcks != -1) {
  227.     status = Sys_Stats(SYS_RPC_NEG_ACKS, rpcNegAcks, NIL);
  228.     }
  229.     if (rpcNumNackBufs != -1) {
  230.     status = Sys_Stats(SYS_RPC_NUM_NACK_BUFS, rpcNumNackBufs, NIL);
  231.     }
  232.     if (rpcChannelNegAcks != -1) {
  233.     status = Sys_Stats(SYS_RPC_CHANNEL_NEG_ACKS, rpcChannelNegAcks, NIL);
  234.     }
  235.     if (rpcEchoHost != (char *)0) {
  236.     status = RpcEcho(rpcEchoHost);
  237.     }
  238.     if (sanityChecks != -1) {
  239.     status = Sys_Stats(SYS_RPC_SANITY_CHECK, sanityChecks, NIL);
  240.     }
  241.     exit(status);
  242. }
  243.  
  244. RpcEcho(server)
  245.     char *server;
  246. {
  247.     Host_Entry *entryPtr;
  248.     int serverID;
  249.     int myID;
  250.     int error;
  251.     char buffer[16 * 1024];
  252.     Time deltaTime;
  253.  
  254.     entryPtr = Host_ByName(server);
  255.     if (entryPtr == (Host_Entry *) NULL) {
  256.     fprintf(stderr, "Unable to get host number for host '%s'\n",
  257.                server);
  258.     exit(1);
  259.     }
  260.     serverID = entryPtr->id;
  261.  
  262.     error = Proc_GetHostIDs((int *) NULL, &myID);
  263.     if (error != SUCCESS) {
  264.     perror( "Proc_GetHostIDs");
  265.     exit(error);
  266.     }
  267.     if (myID == serverID) {
  268.     fprintf(stderr, "Unable to send RPC to yourself.\n");
  269.     exit(1);
  270.     }
  271.     error = DoTest(TEST_RPC_SEND, serverID, numEchoes, blockSize, buffer,
  272.         buffer, &deltaTime);
  273.     if (error != SUCCESS) {
  274.     Stat_PrintMsg(error, "RPC failed:");
  275.     } else {
  276.     printf("Send %d bytes %d.%06d sec\n", blockSize, deltaTime.seconds,
  277.         deltaTime.microseconds);
  278.     }
  279.     return(error);
  280. }
  281. ReturnStatus
  282. DoTest(command, serverID, numEchoes, size, inDataBuffer, outDataBuffer, timePtr)
  283.     int command;
  284.     int serverID;
  285.     int numEchoes;
  286.     int size;
  287.     Address inDataBuffer;
  288.     Address outDataBuffer;
  289.     Time *timePtr;
  290. {
  291.     Rpc_EchoArgs echoArgs;
  292.     ReturnStatus error;
  293.  
  294.     echoArgs.serverID = serverID;
  295.     echoArgs.n = numEchoes;
  296.     echoArgs.size = size;
  297.     echoArgs.inDataPtr = inDataBuffer;
  298.     echoArgs.outDataPtr = outDataBuffer;
  299.     echoArgs.deltaTimePtr = timePtr;
  300.     error = Test_Rpc(command, &echoArgs);
  301.  
  302.     return(error);
  303. }
  304.  
  305. ReturnStatus
  306. SetFlag(command, value, comment)
  307.     int command;        /* Argument to Fs_Command */
  308.     int value;            /* Value for flag */
  309.     char *comment;        /* For Io_Print */
  310. {
  311.     register int newValue;
  312.     register ReturnStatus status;
  313.  
  314.     newValue = value;
  315.     status = Fs_Command(command, sizeof(int), (Address) &value);
  316.     printf("%s %s, was %s\n", comment,
  317.              newValue ? "on" : "off",
  318.              value ? "on" : "off");
  319.     return(status);
  320. }
  321.  
  322.  
  323. /*
  324.  *----------------------------------------------------------------------
  325.  *
  326.  * ResetClientHist --
  327.  *
  328.  *    Reset the client-side histograms.
  329.  *
  330.  * Results:
  331.  *    None.
  332.  *
  333.  * Side effects:
  334.  *    None.
  335.  *
  336.  *----------------------------------------------------------------------
  337.  */
  338.  
  339. static void
  340. ResetClientHist()
  341. {
  342.     ReturnStatus status;
  343.  
  344.     status = Sys_Stats(SYS_RPC_CLIENT_HIST, 0, NULL);
  345.     if (status != SUCCESS) {
  346.     fprintf(stderr, "Can't reset client RPC histograms: %s\n",
  347.         Stat_GetMsg(status));
  348.     }
  349. }
  350.  
  351.  
  352. /*
  353.  *----------------------------------------------------------------------
  354.  *
  355.  * ResetServerHist --
  356.  *
  357.  *    Reset the server-side histograms.
  358.  *
  359.  * Results:
  360.  *    None.
  361.  *
  362.  * Side effects:
  363.  *    None.
  364.  *
  365.  *----------------------------------------------------------------------
  366.  */
  367.  
  368. static void
  369. ResetServerHist()
  370. {
  371.     ReturnStatus status;
  372.  
  373.     status = Sys_Stats(SYS_RPC_SERVER_HIST, 0, NULL);
  374.     if (status != SUCCESS) {
  375.     fprintf(stderr, "Can't reset server RPC histograms: %s\n",
  376.         Stat_GetMsg(status));
  377.     }
  378. }
  379. @
  380.  
  381.  
  382. 1.6
  383. log
  384. @Add -sanity option.  (Mike checking in for John.)
  385. @
  386. text
  387. @d18 1
  388. a18 1
  389. static char rcsid[] = "$Header: /sprite/src/cmds/rpccmd/RCS/rpccmd.c,v 1.5 90/08/29 17:18:31 ouster Exp Locker: jhh $ SPRITE (Berkeley)";
  390. d21 9
  391. a29 9
  392. #include "sprite.h"
  393. #include "status.h"
  394. #include "option.h"
  395. #include "stdio.h"
  396. #include "fs.h"
  397. #include "fsCmd.h"
  398. #include "sysStats.h"
  399. #include "rpc.h"
  400. #include "host.h"
  401. d41 2
  402. d72 4
  403. d98 6
  404. d126 1
  405. a126 1
  406.     argc = Opt_Parse(argc, argv, optionArray, numOptions);
  407. d153 6
  408. a244 15
  409. SetInt(command, value, comment)
  410.     int command;        /* Argument to Fs_Command */
  411.     int value;            /* Value for int */
  412.     char *comment;        /* For Io_Print */
  413. {
  414.     register int newValue;
  415.     register ReturnStatus status;
  416.  
  417.     newValue = value;
  418.     status = Fs_Command(command, sizeof(int), (Address) &value);
  419.     printf("%s %d, was %d\n", comment, newValue, value);
  420.     return(status);
  421. }
  422.  
  423. ReturnStatus
  424. d259 58
  425. @
  426.  
  427.  
  428. 1.6.1.1
  429. log
  430. @Initial branch for Sprite server.
  431. @
  432. text
  433. @d18 1
  434. a18 1
  435. static char rcsid[] = "$Header: /sprite/src/cmds/rpccmd/RCS/rpccmd.c,v 1.6 92/07/09 18:26:10 jhh Exp $ SPRITE (Berkeley)";
  436. @
  437.  
  438.  
  439. 1.5
  440. log
  441. @Added "numPings" option.
  442. @
  443. text
  444. @d18 1
  445. a18 1
  446. static char rcsid[] = "$Header: /sprite/src/cmds/rpccmd/RCS/rpccmd.c,v 1.3 89/08/15 21:11:45 jhh Exp Locker: mgbaker $ SPRITE (Berkeley)";
  447. d49 1
  448. d86 3
  449. a88 1
  450.     
  451. d158 3
  452. @
  453.  
  454.  
  455. 1.4
  456. log
  457. @Added many more options.
  458. @
  459. text
  460. @d48 1
  461. d83 2
  462. d186 2
  463. a187 2
  464.     error = DoTest(TEST_RPC_SEND, serverID, 100, blockSize, buffer, buffer,
  465.         &deltaTime);
  466. @
  467.  
  468.  
  469. 1.3
  470. log
  471. @changed call to Sys_GetMachineInfo to Proc_GetHostIDs
  472. @
  473. text
  474. @d18 1
  475. a18 1
  476. static char rcsid[] = "$Header: /a/newcmds/rpccmd/RCS/rpccmd.c,v 1.2 88/11/11 14:11:19 brent Exp Locker: jhh $ SPRITE (Berkeley)";
  477. d43 5
  478. d68 15
  479. d134 15
  480. @
  481.  
  482.  
  483. 1.2
  484. log
  485. @Added -ping option
  486. @
  487. text
  488. @d18 1
  489. a18 1
  490. static char rcsid[] = "$Header: /a/newcmds/rpccmd/RCS/rpccmd.c,v 1.1 88/10/31 14:28:23 brent Exp $ SPRITE (Berkeley)";
  491. d139 1
  492. a139 1
  493.     error = Sys_GetMachineInfo((int *) NULL, (int *) NULL, &myID);
  494. d141 1
  495. a141 1
  496.     perror( "Sys_GetMachineInfo");
  497. @
  498.  
  499.  
  500. 1.1
  501. log
  502. @Initial revision
  503. @
  504. text
  505. @d18 1
  506. a18 1
  507. static char rcsid[] = "$Header: fsCmd.c,v 1.7 87/08/22 16:26:08 brent Exp $ SPRITE (Berkeley)";
  508. d28 3
  509. d41 2
  510. d49 4
  511. d115 3
  512. d119 61
  513. @
  514.